package com.exam.util;

public class BaseResult<T> {
    private int code;   // 状态码
    private String msg;  // 提示消息
    private T data; // 数据部分

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    // 默认构造方法
    public BaseResult() {}

    // 全参构造方法
    public BaseResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    // 响应成功的静态方法
    public static <T> BaseResult<T> success(T data) {
        return new BaseResult<>(200, "成功", data);
    }

    public static <T> BaseResult<T> success(String msg,T data) {
        return new BaseResult<>(200, msg, data);
    }

    public static <T> BaseResult<T> success() {
        return new BaseResult<>(200, "成功",null);
    }

    public static <T> BaseResult<T> success(String msg) {
        return new BaseResult<>(200, msg,null);
    }

    // 响应失败的静态方法
    public static <T> BaseResult<T> error(int code, String msg) {
        return new BaseResult<>(code, msg, null);
    }

    public static <T> BaseResult<T> error(String msg) {
        return new BaseResult<>(400, msg, null);
    }

    public static <T> BaseResult<T> error(String msg,T data) {
        return new BaseResult<>(400, msg, data);
    }
}

